﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CCWin;
using GroupChat2013.Entity;
using GroupChat2013.Logic;
using GroupChat2013.Common;

namespace GroupChat2013.Main
{
    public partial class FrmClientConfig : CCSkinMain
    {
        private ClientConfigInfo config;

        private ParseConfig<ClientConfigInfo> parseConfig;

        public FrmClientConfig()
        {
            InitializeComponent();
            this.Load += new EventHandler(FrmClientConfig_Load);
        }

        void FrmClientConfig_Load(object sender, EventArgs e)
        {
            parseConfig = GetClientConfigInfo();

            config = parseConfig.Parse();

            nudShowTime.Value = config.NoticeFormConfig.ShowTime;
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            config.NoticeFormConfig.ShowTime = (int)nudShowTime.Value;
            if (parseConfig.SaveConfig(config))
            {
                MessageBoxEx.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBoxEx.Show("保存失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        public static ParseConfig<ClientConfigInfo> GetClientConfigInfo()
        {
            return new ParseConfig<ClientConfigInfo>(EngineContext.Current.FilePathManager.PersonConfigPath,
                     ConstClass.ClientConfigName,
                     () => { return new ClientConfigInfo(); });
        }
    }
}
